import { LOGIN_FAIL, LOGIN_SUCCESS, userAction } from "./userAction";

export interface userState {
  username: string;
  nickname: string;
  isLogin: boolean;
  token: string;
}

const initState: userState = {
  username: "",
  nickname: "",
  isLogin: false,
  token: "",
};

export const userReducer = (state = initState, action: userAction) => {
  switch (action.type) {
    case LOGIN_FAIL: {
      return {
        username: "",
        nickname: "",
        isLogin: false,
        token: "",
      };
    }
    case LOGIN_SUCCESS: {
			return {
				...state,
				...action.payload
			}
    }
    default:
      return state;
  }
};
